﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using Microsoft.SharePoint.Administration;

namespace ServBus.ListForm2010.Setup.Validators
{
    public class TimerValidator : BaseValidator
    {
        public override string CheckItemText
        {
            get { return Properties.Resources.CheckingTimer; }
        }

        public override string ValidText
        {
            get { return Properties.Resources.CheckPassTimer; }
        }

        public override string InvalidText
        {
            get { return Properties.Resources.CheckFailTimer; }
        }

        public override void Validate()
        {
            foreach (SPServer server in SPFarm.Local.Servers)
            {
                foreach (SPServiceInstance svc in server.ServiceInstances)
                {
                    if (svc.GetType().FullName == "Microsoft.SharePoint.Administration.SPTimerServiceInstance")
                    {
                        ServiceController sc = new ServiceController("SPTimerV4", server.Name);
                        if (sc.Status == ServiceControllerStatus.Running)
                        {
                            this.Validated = true;
                            return;
                        }
                        break;
                    }
                }
            }
        }
    }
}
